package com.cloudbroker.bcs.csvc.base.api.constants;

import java.util.Map;

import com.cloudbroker.bcs.csvc.base.api.util.HSBCCSUtil;
import com.cloudbroker.bcs.csvc.base.api.util.HSBCCSUtil.ErrorNoReader;

public class HSBCCSErrorCodes {
    
    /**
     * 成功
     */
    public static final String SUCCESS = "0";
    
    /**
     * 通用错误
     */
    public static final String COMMON_ERROR = "1";
    
    /**
     * 没有这种实现
     */
    public static final String NO_SUCH_IMPL = "2";
    
    /**
     * 不支持该操作
     */
    public static final String UNSUPPORTED_OPERATION = "3";
    
    /**
     * 参数错误
     */
    public static final String PARAM_ERROR = "4";
    
    /**
     * 调用服务提供系统访问失败
     */
    public static final String REMOTE_SERVICE_ACCESS_ERROR = "5";
    
    /**
     * 调用服务提供系统业务失败
     */
    public static final String REMOTE_SERVICE_BIZ_ERROR = "6";
    
    /**
     * 调用服务提供系统回应异常（验签失败等）
     */
    public static final String REMOTE_RESPONSE_INVALID = "7";
    
    public static ErrorNoReader errorNoReader = new ErrorNoReader() {
        @Override
        public String getErrorNo(Map<String, Object> result) {
            Object errorNo = result.get(HSBCCSFields.ERROR_NO);
            return null == errorNo ? null : String.valueOf(errorNo);
        }
    };
    
    public static boolean isSuccess(Map<String, Object> result) {
        return HSBCCSUtil.isSuccess(result, errorNoReader, SUCCESS);
    }
    
    public static boolean isErrorOf(Map<String, Object> result, String errorNo) {
        return HSBCCSUtil.isErrorOf(result, errorNoReader, errorNo);
    }
    
    public static boolean isSuccessOrBizError(Map<String, Object> result) {
        if (null == result) {
            return false;
        }
        String errorNo = errorNoReader.getErrorNo(result);
        return null == errorNo || SUCCESS.equals(errorNo) || REMOTE_SERVICE_BIZ_ERROR.equals(errorNo);
    }
    
    public static boolean isErrorIn(Map<String, Object> result, String... errorNos) {
        return HSBCCSUtil.isErrorIn(result, errorNoReader, errorNos);
    }
    
}
